package com.work.leecode.array.easy;

/**
 * @author huangxianjin <huangxianjin@kuaishou.com>
 * Created on 2024-04-12
 */

/**
 * 买卖股票最佳时机---121
 */
public class Lc121 {
    public int maxProfit(int[] prices) {
        int minPrice = Integer.MAX_VALUE;
        int maxProfit = 0;
        for (int i = 0; i < prices.length; i++) {
            if (prices[i] < minPrice) {
                minPrice = prices[i];
            } else if (prices[i] - minPrice > maxProfit) {
                maxProfit = prices[i] - minPrice;
            }
        }
        return maxProfit;
    }
}
